package com.example.psychologicalappointmentsystem.Controller;

import com.example.psychologicalappointmentsystem.Object.ConsultationTimeVO;
import com.example.psychologicalappointmentsystem.Object.OrderVO;
import com.example.psychologicalappointmentsystem.Object.UserLoginRequest;
import com.example.psychologicalappointmentsystem.service.OrderService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;

@RestController
@RequestMapping("/api/order")  // 处理用户相关请求的控制器，所有路径以 "/api/user" 开头
public class OrderController {
    @Autowired
    OrderService orderService;

    @ApiOperation("创建订单")
    @RequestMapping(value = "/create", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
    public ResponseEntity<?> createOrder(@RequestBody OrderVO orderVO) {
        return orderService.createOrder(orderVO);
    }

    @ApiOperation("获取订单列表")
    @ApiImplicitParams({
            // 分页
            @ApiImplicitParam(name = "current", value = "查询页码", dataType = "Integer", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "pageSize", value = "页数据量", dataType = "Integer", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "consultant_id", value = "咨询师id", dataType = "Integer", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "user_id", value = "用户id", dataType = "Integer", dataTypeClass = Integer.class),

    })
    @RequestMapping(value = "/list/page", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
    public ResponseEntity<?> orderList(@RequestBody OrderVO orderVO) {
        return orderService.orderListPage(orderVO);
    }

    @ApiOperation("获取订单详情")
    @RequestMapping(value = "/info", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
    public ResponseEntity<?> orderinfo(@RequestBody OrderVO orderVO) {
        return orderService.orderInfo(orderVO);
    }

    @ApiOperation("咨询师可选时间")
    @ApiImplicitParams({
            // 分页
            @ApiImplicitParam(name = "consultant_id", value = "咨询师id", dataType = "Integer", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "date", value = "日期", dataType = "Integer", dataTypeClass = Integer.class)
    })
    @RequestMapping(value = "/selectTime", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
    public ResponseEntity<?> selectTime(@RequestBody ConsultationTimeVO consultationTimeVO) {
        return orderService.selectTime(consultationTimeVO);
    }

    @ApiOperation("订单支付")
    @ApiImplicitParams({
            // 分页
            @ApiImplicitParam(name = "orderId", value = "订单id", dataType = "Integer", dataTypeClass = Integer.class),
    })
    @RequestMapping(value = "/payment", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
    public ResponseEntity<?> payment(@RequestParam("orderId") Long orderId) {
        return orderService.payment(orderId);
    }

//    @ApiOperation("支付结果通知回调地址")
//    @ApiImplicitParams({
//            // 分页
//            @ApiImplicitParam(name = "orderId", value = "订单id", dataType = "Integer", dataTypeClass = Integer.class),
//    })
//    @RequestMapping(value = "/payment", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
//    public ResponseEntity<?> paymentResult(@RequestParam("orderId") Long orderId) {
//        return orderService.paymentResult(orderId);
//    }


    @ApiOperation("咨询师接受预约")
    @ApiImplicitParams({
            // 分页
            @ApiImplicitParam(name = "orderId", value = "订单id", dataType = "Integer", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "acceptStatus", value = "咨询师接受状态，0-取消预约，1-接受预约", dataType = "Integer", dataTypeClass = Integer.class),
    })
    @RequestMapping(value = "/accept", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
    public ResponseEntity<?> accept(@RequestBody ConsultationTimeVO consultationTimeVO) {
        return orderService.consultantAccept(consultationTimeVO);
    }

    @ApiOperation("查看当前预约")
    @ApiImplicitParams({

    })
    @RequestMapping(value = "/orderLast", method = RequestMethod.GET, produces = "application/json; charset=utf-8")
    public ResponseEntity<?> orderLast() {
        return orderService.orderAcceptInfo();
    }


}
